package com.cedarpark.manic8ball;

import java.util.Calendar;
import java.util.Random;

import android.app.Activity;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.Window;
import android.view.WindowManager;
import android.view.GestureDetector.OnGestureListener;
import android.widget.TextView;

public class FortuneActivity extends Activity implements OnGestureListener {
	
	TextView versionText;
	GestureDetector mGestureDetector; 
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
      
        // remove window title
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
        		WindowManager.LayoutParams.FLAG_FULLSCREEN); 

        mGestureDetector = new GestureDetector(this);
        mGestureDetector.setIsLongpressEnabled(true); 
        
        setContentView(R.layout.main);
        versionText = (TextView) findViewById(R.id.theAnswer);
        
    }	
  
	private void giveFortune() {
		versionText.setText(askQuestion());
	}
	
	public static String askQuestion() {
		String answers[] = {
        "As I see\n it, yes",
        "Are\n you\n kidding?",
        "Better\n not tell\n you now",
        "Probably",
        "Concentrate\n and ask\n again",
        "Don't\n count\n on it",
        "It\n is certain",
        "It is\n decidedly so",
        "Most\n Likely",
        "My\n sources\n say no",
        "My\n reply\n is no",
        "Not\n Likely",
        "Outlook\n good",
        "Outlook\n not\n so good",
        "Reply\n hazy try\n again",
        "Signs\n Point\n to Yes",
        "Very\n doubtful",
        "Without\n a doubt",
        "Yes",
        "Yes",
        "You\n may rely\n on it"};

		
		Calendar calendar = Calendar.getInstance();
		java.util.Random r = new Random(calendar.getTimeInMillis());
		java.lang.Double d = new Double((r.nextDouble() * answers.length) - 1);
		return new String(answers[d.intValue()]);
	}

	@Override
	public boolean onDown(MotionEvent e) {
		giveFortune();
		return true;
		
	}

	@Override
	public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
			float velocityY) {
		return false;
	}

	@Override
	public void onLongPress(MotionEvent e) {
	}

	@Override
	public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
			float distanceY) {
		return false;
	}


	@Override
	public void onShowPress(MotionEvent e) {
	}

	@Override
	public boolean onSingleTapUp(MotionEvent arg0) {
		return false;
	}
	
    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
    	return mGestureDetector.onTouchEvent(ev); 
    }
	
}